Dockerizing a Javascript
Dockerizing a Javascript Project
So this is a basic example of a docker file
FROM node:16
COPY . ./
RUN npm install
CMD \["node","index.js"\]
Assuming this is our folder structure
|-index.js
|-package.JSON
|-dockerfile
Here is each line in the docker file:
-
Set the base image to the node runtime
-
Copy our project, into / in the image
-
Run npm install to get dependencies
-
The run command (which will be run when the image is run) is set to
node index.js
Finally we can build and run it like so
docker build -t imagename .
docker run imagename